﻿
using System;
using System.Drawing;
using System.Windows.Forms;
using GlassUI;

namespace DemoApp
{
    public partial class Form1 : GlassForm
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void glassButton1_Click(object sender, EventArgs e)
        {
            StackedPanel page = new StackedPanel();
            page.Text = string.Format("stackedPanel{0}", stackedPanelControl1.Controls.Count + 1);
            page.HeaderBackColor = RandomColor();
            page.Padding = new Padding(3);
            stackedPanelControl1.StackedPanels.Add(page);
        }

        private void glassButton2_Click(object sender, EventArgs e)
        {
            Form form = new Form2();
            form.ShowDialog(this);
        }

        private void exitToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            switch (this.glassTextBox1.TextAlign)
            {
                case HorizontalAlignment.Center:
                    this.glassTextBox1.TextAlign = HorizontalAlignment.Right;
                    break;
                case HorizontalAlignment.Right:
                    this.glassTextBox1.TextAlign = HorizontalAlignment.Left;
                    break;
                default:
                    this.glassTextBox1.TextAlign = HorizontalAlignment.Center;
                    break;
            }

        }

        private Random rndm = new Random();

        private Color RandomColor()
        {
            return Color.FromArgb(rndm.Next(256), rndm.Next(256), rndm.Next(256));
        }

        private void glassListView1_DrawItem(object sender, DrawListViewItemEventArgs e)
        {
            if (e.DrawDefault)
                e.Graphics.FillRectangle(Brushes.White, e.Bounds);
            e.DrawBackground();
            e.DrawFocusRectangle();
        }

        private void glassListView1_DrawSubItem(object sender, DrawListViewSubItemEventArgs e)
        {
            if (e.DrawDefault)
                e.Graphics.FillRectangle(Brushes.White, e.Bounds);
            e.DrawBackground();
            e.DrawText();
        }

        private void glassListView1_DrawGroup(object sender, DrawListViewGroupEventArgs e)
        {
            e.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
            e.Graphics.DrawString(e.HeaderText, e.Font, Brushes.Red, e.Bounds);
        }

        private void glassListView1_DrawColumnHeader(object sender, DrawListViewColumnHeaderEventArgs e)
        {
            Brush fillBrush = Brushes.Green;

            if ((e.State & ListViewItemStates.Selected) == ListViewItemStates.Selected)
                fillBrush = Brushes.Blue;

            if (e.State == ListViewItemStates.Hot)
                fillBrush = Brushes.Red;

            e.Graphics.FillRectangle(fillBrush, e.Bounds);
            using (StringFormat sf = new StringFormat(StringFormatFlags.NoWrap))
            {
                sf.LineAlignment = StringAlignment.Center;
                e.Graphics.DrawString(e.Header.Text, e.Font, Brushes.White, e.Bounds, sf);
            }
        }

    }
}